
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class ContactComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public ContactComponent()
        {

        }
		
		/// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public Contact SelectOne(int ContactId)
        {  
			PlacementManager.DAL.Contact_DAL o = new PlacementManager.DAL.Contact_DAL();
			o.ContactId = ContactId;
			DataTable dt = o.SelectOne().Tables[0];
			
			if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
				PlacementManager.Contact ContactToReturn = new PlacementManager.Contact((int)row["ContactId"], (string)row["FirstName"], (string)row["LastName"], (string)row["Title"], (string)row["JobTitle"], (string)row["EmailAddress"], (bool)row["IsAgency"], (bool)row["IsEducator"], (int)row["EducatorTypeId"], (decimal)row["EducatorCurrentRate"], (bool)row["IsActive"], (int)row["DivisionId"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]);
				return ContactToReturn;
			}
			else
			{
				PlacementManager.Contact ContactToReturnEmpty = new PlacementManager.Contact();
                return ContactToReturnEmpty;
			}
        }
		
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<Contact> SelectAll(string sortExpression)
        {
            List<Contact> listContact = new List<Contact>();
            PlacementManager.DAL.Contact_DAL o = new PlacementManager.DAL.Contact_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listContact.Add(new Contact((int)row["ContactId"], (string)row["FirstName"], (string)row["LastName"], (string)row["Title"], (string)row["JobTitle"], (string)row["EmailAddress"], (bool)row["IsAgency"], (bool)row["IsEducator"], (int)row["EducatorTypeId"], (decimal)row["EducatorCurrentRate"], (bool)row["IsActive"], (int)row["DivisionId"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listContact.Sort(new ContactComparer(sortExpression));
            return listContact;
        }
	
		/// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<Contact> SelectAllWDivisionId(int DivisionId, string sortExpression)
		{
			List<Contact> listContact = new List<Contact>();
			PlacementManager.DAL.Contact_DAL o = new PlacementManager.DAL.Contact_DAL();
			o.DivisionId = DivisionId;
			DataSet ds = o.SelectAllWDivisionId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listContact.Add(new Contact((int)row["ContactId"], (string)row["FirstName"], (string)row["LastName"], (string)row["Title"], (string)row["JobTitle"], (string)row["EmailAddress"], (bool)row["IsAgency"], (bool)row["IsEducator"], (int)row["EducatorTypeId"], (decimal)row["EducatorCurrentRate"], (bool)row["IsActive"], (int)row["DivisionId"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listContact.Sort(new ContactComparer(sortExpression));
			return listContact;
		}


		/// <summary>
        /// Inserts a new row into the datatable.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(Contact o)
        {	
            PlacementManager.DAL.Contact_DAL oContact = new PlacementManager.DAL.Contact_DAL();
			oContact.FirstName = o.FirstName;
			oContact.LastName = o.LastName;
			oContact.Title = o.Title;
			oContact.JobTitle = o.JobTitle;
			oContact.EmailAddress = o.EmailAddress;
			oContact.IsAgency = o.IsAgency;
			oContact.IsEducator = o.IsEducator;
			oContact.EducatorTypeId = o.EducatorTypeId;
			oContact.EducatorCurrentRate = o.EducatorCurrentRate;
			oContact.IsActive = o.IsActive;
			oContact.DivisionId = o.DivisionId;
			oContact.DateCreated = o.DateCreated;
			oContact.CreatedBy = o.CreatedBy;
			oContact.DateUpdated = o.DateUpdated;
			oContact.UpdatedBy = o.UpdatedBy;

            return oContact.Insert();
        }
		
		/// <summary>
        /// Inserts a new row into the datatable by passing parameters represneting each column.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(string FirstName, string LastName, string Title, string JobTitle, string EmailAddress, bool IsAgency, bool IsEducator, int EducatorTypeId, decimal EducatorCurrentRate, bool IsActive, int DivisionId, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.Contact_DAL oContact = new PlacementManager.DAL.Contact_DAL();

			oContact.FirstName = FirstName;
			oContact.LastName = LastName;
			oContact.Title = Title;
			oContact.JobTitle = JobTitle;
			oContact.EmailAddress = EmailAddress;
			oContact.IsAgency = IsAgency;
			oContact.IsEducator = IsEducator;
			oContact.EducatorTypeId = EducatorTypeId;
			oContact.EducatorCurrentRate = EducatorCurrentRate;
			oContact.IsActive = IsActive;
			oContact.DivisionId = DivisionId;
			oContact.DateCreated = DateCreated;
			oContact.CreatedBy = CreatedBy;
			oContact.DateUpdated = DateUpdated;
			oContact.UpdatedBy = UpdatedBy;

            return oContact.Insert();
        }

		/// <summary>
        /// Updates a row in the database table based on the primary key.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(Contact o)
        {	
            PlacementManager.DAL.Contact_DAL oContact = new PlacementManager.DAL.Contact_DAL();
			oContact.ContactId = o.ContactId;
			oContact.FirstName = o.FirstName;
			oContact.LastName = o.LastName;
			oContact.Title = o.Title;
			oContact.JobTitle = o.JobTitle;
			oContact.EmailAddress = o.EmailAddress;
			oContact.IsAgency = o.IsAgency;
			oContact.IsEducator = o.IsEducator;
			oContact.EducatorTypeId = o.EducatorTypeId;
			oContact.EducatorCurrentRate = o.EducatorCurrentRate;
			oContact.IsActive = o.IsActive;
			oContact.DivisionId = o.DivisionId;
			oContact.DateCreated = o.DateCreated;
			oContact.CreatedBy = o.CreatedBy;
			oContact.DateUpdated = o.DateUpdated;
			oContact.UpdatedBy = o.UpdatedBy;

            return oContact.Update();
        }
		
		/// <summary>
        /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(int ContactId, string FirstName, string LastName, string Title, string JobTitle, string EmailAddress, bool IsAgency, bool IsEducator, int EducatorTypeId, decimal EducatorCurrentRate, bool IsActive, int DivisionId, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.Contact_DAL oContact = new PlacementManager.DAL.Contact_DAL();

			oContact.ContactId = ContactId;
			oContact.FirstName = FirstName;
			oContact.LastName = LastName;
			oContact.Title = Title;
			oContact.JobTitle = JobTitle;
			oContact.EmailAddress = EmailAddress;
			oContact.IsAgency = IsAgency;
			oContact.IsEducator = IsEducator;
			oContact.EducatorTypeId = EducatorTypeId;
			oContact.EducatorCurrentRate = EducatorCurrentRate;
			oContact.IsActive = IsActive;
			oContact.DivisionId = DivisionId;
			oContact.DateCreated = DateCreated;
			oContact.CreatedBy = CreatedBy;
			oContact.DateUpdated = DateUpdated;
			oContact.UpdatedBy = UpdatedBy;

            return oContact.Update();
        }
		
		/// <summary>
        /// Deletes one row in the database table.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(Contact o)
        {
            PlacementManager.DAL.Contact_DAL oContact_DAL = new PlacementManager.DAL.Contact_DAL();
            oContact_DAL.ContactId = o.ContactId;
            return oContact_DAL.Delete();
        }
		
		/// <summary>
        /// Deletes one row in the database table by passing the primary key.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(int ContactId)
        {
            PlacementManager.DAL.Contact_DAL oContact_DAL = new PlacementManager.DAL.Contact_DAL();
            oContact_DAL.ContactId = ContactId;
            return oContact_DAL.Delete();
        }
		
		/// <summary>
		/// Deletes all rows in a table based on a foreign key.
		/// </summary>
		/// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWDivisionId(int DivisionId)
		{
			PlacementManager.DAL.Contact_DAL oContact_DAL = new PlacementManager.DAL.Contact_DAL();
			oContact_DAL.DivisionId = DivisionId;			
			return oContact_DAL.DeleteAllWDivisionId();
		}

	}
	
	public class ContactComparer : IComparer<Contact>
    {
        private string _sortColumn;
        private bool _reverse;

        public ContactComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(Contact a, Contact b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "ContactId":
					retVal = String.Compare(a.ContactId.ToString(), b.ContactId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "FirstName":
					retVal = String.Compare(a.FirstName.ToString(), b.FirstName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "LastName":
					retVal = String.Compare(a.LastName.ToString(), b.LastName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Title":
					retVal = String.Compare(a.Title.ToString(), b.Title.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "JobTitle":
					retVal = String.Compare(a.JobTitle.ToString(), b.JobTitle.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "EmailAddress":
					retVal = String.Compare(a.EmailAddress.ToString(), b.EmailAddress.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsAgency":
					retVal = String.Compare(a.IsAgency.ToString(), b.IsAgency.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsEducator":
					retVal = String.Compare(a.IsEducator.ToString(), b.IsEducator.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "EducatorTypeId":
					retVal = String.Compare(a.EducatorTypeId.ToString(), b.EducatorTypeId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "EducatorCurrentRate":
					retVal = String.Compare(a.EducatorCurrentRate.ToString(), b.EducatorCurrentRate.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsActive":
					retVal = String.Compare(a.IsActive.ToString(), b.IsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DivisionId":
					retVal = String.Compare(a.DivisionId.ToString(), b.DivisionId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateCreated":
					retVal = String.Compare(a.DateCreated.ToString(), b.DateCreated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CreatedBy":
					retVal = String.Compare(a.CreatedBy.ToString(), b.CreatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateUpdated":
					retVal = String.Compare(a.DateUpdated.ToString(), b.DateUpdated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UpdatedBy":
					retVal = String.Compare(a.UpdatedBy.ToString(), b.UpdatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
